package com.rp.infopub.dao;

import java.util.List;

import org.raptor.common.DbOperUtil;
import org.raptor.orm.hibernate.DbaHibernateTemplateSupport;
import org.raptor.pagination.Page2;
import org.springframework.stereotype.Repository;

import com.rp.common.vo.PageParam;
import com.rp.infopub.po.Channel;

@Repository
public class ChannelDao extends DbaHibernateTemplateSupport<Channel> {

	public static final String INSERT_CHANNEL = 
			"INSERT INTO RP_INFOPUB_CHANNELS(id,createDate,updateDate,version,enabled2,name,pid,creatorId,creatorName,ip,remark) " +
			"VALUES(?,?,?,?,?,?,?,?,?,?,?)";
	
	public List<Channel> getAllChannel(){
		String hql = "from Channel"+DbOperUtil.generateOrderBy("createDate", "desc");
		return this.find(hql);
	}
	
	/**
	 * 根据栏目编号获取栏目列表
	 * @param number
	 * @return
	 */
	public List<Channel> getChannelsByNumber(String number){
		String hql = "from Channel where number = ?"+DbOperUtil.generateOrderBy("createDate", "desc");
		return this.find(hql, number);
	}
	
	/**
	 * 根据栏目编号分页获取栏目数据
	 * @param pageParam
	 * @param number
	 * @return
	 */
	public Page2 getChannelsByNumber(PageParam pageParam, String number){
		String hql = "from Channel where number = ?"+DbOperUtil.generateOrderBy("createDate", "desc");
		return this.getPage2ByOffset(hql, 
				pageParam.getPageIndex(), pageParam.getPageSize(), 
				pageParam.getSortField(), pageParam.getSortOrder(), 
				number);
	}
	
}
